package com.tem.controller;

import com.alibaba.fastjson.JSON;
import com.tem.domain.User;
import com.tem.service.IUserService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.Size;
import java.util.List;

/**
 * @Author: tiger
 * @Date:2018/4/28
 * @Description:测试Action
 */
@RestController
public class TestController {
    private final Logger logger = Logger.getLogger(TestController.class);

    @RequestMapping("/index")
    public String indes(Model model) {
        String test = "nihao spring mvc...";
        model.addAttribute("model", test);
        return "index";
    }

    @RequestMapping("/test")
    public void test() {
        System.out.println("hello ...");
    }

    @GetMapping("/restTest/{param}")
    public String restTest(@PathVariable("param") String param, Model model) {
        model.addAttribute("model", param);
        return "index";
    }

    @RequestMapping("/testValid")
    public String testValid(@Size(max = 100, min = 0, message = "大小有误") Long age, BindingResult result, Model model) {
        if (result.hasErrors()) {
            return "error";
        }
        model.addAttribute("model", age);
        return "index";
    }
}
